def solve(prices):
    n = len(prices)
    dp = [[i for i in range(2)] for i in range(n)]
    # print(dp)
    dp[0][0] = 0
    dp[0][1] = -prices[0]
    for i in range(1, n):
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i])
        dp[i][1] = max(dp[i - 1][0] - prices[i], dp[i - 1][1])

    return dp[n - 1][0]


if __name__ == "__main__":
    prices = [7, 1, 5, 3, 6, 4]
    print(solve(prices))
